//在main.js中的最前面引入babel-polyfill
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import '@/assets/styles/main.scss'
import router from './router'
import store from './vuex/store.js'
import VueCookies from 'vue-cookies'

//关闭生产环境下的提示
Vue.config.productionTip = false
//全局按需引入的UI组件
import {
    Button,
    Select,
    Option,
    Notification,
    Message,
    Checkbox,
    CheckboxGroup,
    Loading,
    Tabs,
    TabPane,
    Carousel,
    CarouselItem,
    Form,
    FormItem,
    Input,
    DatePicker,
    InputNumber,
    Upload,
    Cascader,
    Row,
    Col,
    Table,
    TableColumn,
    Progress,
    Dialog,
    Pagination,
    Badge,
    Tag,
    Breadcrumb,
    BreadcrumbItem,
    ButtonGroup,
    Tooltip,
    Radio,
    RadioGroup,
    Dropdown,
    DropdownMenu,
    DropdownItem,
    Icon,
    Card,
    Popover,
    Menu,
    Submenu,
    MenuItem,
    MenuItemGroup,
} from 'element-ui';
// collapse 展开折叠
// fade/zoom 等
import 'element-ui/lib/theme-chalk/base.css';
import CollapseTransition from 'element-ui/lib/transitions/collapse-transition';

Vue.use(VueCookies)

Vue.component(CollapseTransition.name, CollapseTransition)
Vue.use(Button)
Vue.use(Select)
Vue.use(Option)
Vue.use(Checkbox)
Vue.use(CheckboxGroup)
Vue.use(TabPane)
Vue.use(Tabs)
Vue.use(CarouselItem)
Vue.use(Carousel)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Input)
Vue.use(DatePicker)
Vue.use(InputNumber)
Vue.use(Upload)
Vue.use(Cascader)
Vue.use(Row)
Vue.use(Col)
Vue.use(Table)
Vue.use(TableColumn)
Vue.use(Progress)
Vue.use(Dialog)
Vue.use(Pagination);
Vue.use(Badge);
Vue.use(Tag);
Vue.use(Breadcrumb);
Vue.use(BreadcrumbItem);
Vue.use(ButtonGroup);
Vue.use(Tooltip);
Vue.use(Radio);
Vue.use(RadioGroup);
Vue.use(Dropdown);
Vue.use(DropdownMenu);
Vue.use(DropdownItem);
Vue.use(Icon);
Vue.use(Card);
Vue.use(Popover);
Vue.use(Menu);
Vue.use(Submenu);
Vue.use(MenuItem);
Vue.use(MenuItemGroup);
Vue.use(Loading.directive);

Vue.prototype.$notify = Notification;
Vue.prototype.$message = Message;
Vue.prototype.$loading = Loading.service;

import countTo from 'vue-count-to'
Vue.use(countTo)

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    store,
    template: '<App/>',
    components: {
        App
    }
})

/**权限指令**/
Vue.directive('has', {
    bind: function (el, binding) {
        if (!Vue.prototype.$_has(binding.value)) {
            el.parentNode.removeChild(el);
        }
    }
});
//权限检查方法
Vue.prototype.$_has = function (value) {
    let isExist = false;
    let buttonpermsStr = localStorage.getItem("perms");
    if (buttonpermsStr == undefined || buttonpermsStr == null) {
        return false;
    }
    let buttonperms = JSON.parse(buttonpermsStr);
    for (let i = 0; i < buttonperms.length; i++) {
        if (buttonperms[i].perms.indexOf(value) > -1) {
            isExist = true;
            break;
        }
    }
    return isExist;
};
